package com.mobile.liuyi_s.orderlunch.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.test.mock.MockApplication;
import android.util.Log;
import android.widget.TextView;

import com.mobile.liuyi_s.orderlunch.MyApplication;
import com.mobile.liuyi_s.orderlunch.R;
import com.mobile.liuyi_s.orderlunch.entity.Order;

import java.util.ArrayList;
import java.util.List;

public class OrderDetailActivity extends AppCompatActivity {

    private static final String TAG = "OrderDetailActivity";
    private MyApplication mApplication;
    private List<Order> mOrders;

    private Toolbar mToolbar;
    private TextView mTextViewOrderUser;
    private TextView mTextViewOrderNum;
    private TextView mTextViewOrderReason;
    private String mOrderUserName;
    private String mOrderNum;
    private String mOrderReason = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        mApplication = ((MyApplication) getApplication());
        initView();
        initData();
        mTextViewOrderUser.setText("姓名：" + mOrderUserName);
        mTextViewOrderNum.setText("数量：" + mOrderNum);
        mTextViewOrderReason.setText("超过两份原因："+mOrderReason);
    }
    private void initView() {
        initToolbar();
        mTextViewOrderUser = ((TextView) findViewById(R.id.txt_order_detail_name));
        mTextViewOrderNum= ((TextView) findViewById(R.id.txt_order_detail_num));
        mTextViewOrderReason = ((TextView) findViewById(R.id.txt_order_detail_reason));
    }
    private void initToolbar() {
        mToolbar = ((Toolbar) findViewById(R.id.toolbar_order_detail));
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);
    }

    private void initData() {
        Intent intent = getIntent();
        String site = intent.getStringExtra("site");
        int position = intent.getIntExtra("position",-1);
        if (site != null) {
            switch (site) {
                case "50":
                    mOrders = mApplication.getOrderList50();
                    break;
                case "51":
                    mOrders = mApplication.getOrderList51();
                    break;
                case "52":
                    mOrders = mApplication.getOrderList52();
                    break;
                case "53":
                    mOrders = mApplication.getOrderList53();
                    break;
                case "54":
                    mOrders = mApplication.getOrderList54();
                    break;
                default:
                    break;
            }
        } else {
            Log.d(TAG, "onCreate: site = null");
        }

        if (position != -1) {
            mOrderUserName = mOrders.get(position).getOrderUser();
            mOrderNum = String.valueOf(mOrders.get(position).getOrderNum());
            mOrderReason = mOrders.get(position).getOrderReason();
        }
    }

}
